/**
 * com.cnhis.his.customer.service.Bdi1Service.java
 */
package com.mbmed.doctor.medadvice.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mbmed.doctor.commons.mapper.ModelVo;
import com.mbmed.doctor.medadvice.bo.Bdi1Bo;
import com.mbmed.doctor.medadvice.mapper.Bdi1;

/**
 * @file  Bdi1Service.java
 * @author 刘武
 * @version 0.1
 * @todo	Bdi1服务操作接口
 * Copyright(C), 2013-2014
 *		 Shenzhen Coordinates Software Development Co., Ltd.
 * History
 *   	1. Date: 2014-10-24 09:44:13
 *      	Author: 刘武
 *      	Modification: this file was created
 *   	2. ...
 */
@Path("/bdi1")
@Component
public class Bdi1Service {
	
	private static Logger logger = Logger.getLogger(Bdi1.class);
	
	@Autowired
	private Bdi1Bo bdi1Bo;
	
	@Context
	Request request;

	
	/**
	 * 查找所有数据库记录
     * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
     */
	@GET
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public List<Bdi1> getAll() throws Exception{
        List<Bdi1> list = new ArrayList<Bdi1>();
        return bdi1Bo.getAll();        
    }
	
    /**
     * 查找符合条件的所有数据库记录
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("{id}")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public Bdi1 getBdi1(@PathParam("id") String id) throws Exception{
    	Bdi1 bdi1 = null;
    	return bdi1Bo.get(id);        
    }
	
	
	/**
     * 查询执行频率
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getadivcebdi1")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo getAdivceBdi1(@QueryParam("advicebtn") java.lang.String advicebtn) throws Exception{
		
		ModelVo modelvo = new ModelVo();
		
		int btn = Integer.parseInt(advicebtn);
		Map<String, String> paramsMap = null;
		switch (btn) {
		case 0:
			//描述医嘱
			paramsMap = new HashMap<String, String>();
			paramsMap.put("aBDI12", "2");
			paramsMap.put("aACF01", "2");
			paramsMap.put("msadvice", "msadvice");
			break;
		case 3:
			paramsMap = new HashMap<String, String>();
			paramsMap.put("aBDI12", "1");
			paramsMap.put("aACF01", "2");
			paramsMap.put("zcyadvice", "zcyadvice");
			break;
		case 2:
			paramsMap = new HashMap<String, String>();
			paramsMap.put("aBDI12", "1");
			paramsMap.put("aACF01", "2");
			paramsMap.put("xcyadvice", "xcyadvice");
			break;
		case 4:
			paramsMap = new HashMap<String, String>();
			paramsMap.put("aBDI12", "2");
			paramsMap.put("aACF01", "2");
			paramsMap.put("jcadvice", "jcadvice");
			break;
		case 5:
			paramsMap = new HashMap<String, String>();
			paramsMap.put("aBDI12", "2");
			paramsMap.put("aACF01", "2");
			paramsMap.put("jyadvice", "jyadvice");
			break;
		case 6:
			paramsMap = new HashMap<String, String>();
			paramsMap.put("aBDI12", "2");
			paramsMap.put("aACF01", "2");
			paramsMap.put("ssadvice", "ssadvice");
			break;
		case 8:
			paramsMap = new HashMap<String, String>();
			paramsMap.put("aBDI12", "2");
			paramsMap.put("aACF01", "2");
			paramsMap.put("wscladvice", "wscladvice");
			break;
		case 7:
			paramsMap = new HashMap<String, String>();
			paramsMap.put("aBDI12", "2");
			paramsMap.put("aACF01", "2");
			paramsMap.put("wscladvice", "wscladvice");
			break;
		default:
			break;
		}
		
		 List<Bdi1> list = new ArrayList<Bdi1>();
		 list = bdi1Bo.getAdivceBdi1(paramsMap);
		 if(null!=list){
			 modelvo.setList(list);
		 }
		
    	return modelvo;
	}
	
	
	
	
	/**
     * 查询一次性执行频率
     * @param vo 与数据库中记录对应的值对象
     * @return type : 返回插入操作是否成功
     * @throws Exception
     */
	@GET
	@Path("/getadviceonce")
	@Produces({MediaType.APPLICATION_JSON})
	public ModelVo getAdviceOnce() throws Exception {
		ModelVo modelVo = new ModelVo();
		Bdi1 bdi1 = new Bdi1();
		bdi1 = bdi1Bo.getAdviceOnce();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("bdi1", bdi1);
		modelVo.setMap(map);
		return modelVo;
				
	}
	
    /**
     * 向数据库中插入一条记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : 返回插入操作是否成功
     * @throws Exception
     */
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public Bdi1 saveBdi1(
			@FormParam("bdi01") java.lang.String bdi01,
			@FormParam("bdi02") java.lang.String bdi02,
			@FormParam("bdi03") java.lang.String bdi03,
			@FormParam("abbrp") java.lang.String abbrp,
			@FormParam("abbrw") java.lang.String abbrw,
			@FormParam("bdi06") java.lang.Integer bdi06,
			@FormParam("bdi07") java.lang.Integer bdi07,
			@FormParam("bdi08") java.lang.String bdi08,
			@FormParam("bdi09") java.lang.String bdi09,
			@FormParam("bdi10") java.lang.Byte bdi10,
			@FormParam("rownr") java.lang.Integer rownr,
			@FormParam("bdi12") java.lang.Byte bdi12,
			@FormParam("acf01") java.lang.Byte acf01,
			@Context HttpServletResponse servletResponse
	) throws Exception {
		Bdi1 bdi1 = new Bdi1();
		bdi1.setBdi01(bdi01);
		bdi1.setBdi02(bdi02);
		bdi1.setBdi03(bdi03);
		bdi1.setAbbrp(abbrp);
		bdi1.setAbbrw(abbrw);
		bdi1.setBdi06(bdi06);
		bdi1.setBdi07(bdi07);
		bdi1.setBdi08(bdi08);
		bdi1.setBdi09(bdi09);
		bdi1.setBdi10(bdi10);
		bdi1.setRownr(rownr);
		bdi1.setBdi12(bdi12);
		bdi1.setAcf01(acf01);

		return bdi1 = bdi1Bo.save(bdi1);

	}
	/**
     * 删除数据库中与传入的值对象对应的记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : boolean 返回删除操作是否成功
     * @throws Exception
     */
	@DELETE
	@Path("{id}")
	public boolean removeBdi1(@PathParam("id") String id) throws Exception{
		if(id == null) return false;
    	return bdi1Bo.remove(id);

	}
	
}
